@extends('layouts.admin')
@section('title')
    <title>hair列表页</title>
@endsection
@section('content')
    @include('layouts.left')
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
               Hair列表
                <small>Control panel</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active">Dashboard</li>
            </ol>
        </section>
        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title"><a type="button" class="btn btn-block btn-success" href="{{ url('hair') }}/create">add hair</a></h3>
                            @if(session('info'))
                                <div class="alert alert-warning alert-dismissible">
                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                    <h4><i class="icon fa fa-warning"></i> Alert!</h4>
                                    {{ session('info') }}
                                </div>
                            @endif
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body">
                            <table id="example2" class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th></th>
                                    <th>id</th>
                                    <th>名称</th>
                                    <th>类型</th>
                                    <th>款式</th>
                                    <th>缩略图</th>
                                    <th>排序</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody class="mparent">
                                @foreach($datas as $k=>$data)
                                        <tr>
                                            <td><input type="checkbox" value="{{$data -> hairid}}" name="hair[]"></td>
                                            <td>{{ $data -> hairid }}</td>
                                            <td>{{ $data -> hairname }}</td>
                                            <td >
                                                @if($data -> hairtype  == '1' )
                                                   short
                                                @else
                                                    long
                                                @endif
                                            </td>
                                            <td >
                                                @if($data -> hairsex  == '1' )
                                                   女
                                                @else
                                                    男
                                                @endif
                                            </td>
                                            <td><img src="http://img1.shishikeji.cn/{{ $data -> hairthumb }}"></td>
                                            <td>{{ $data -> sort }}</td>
                                            <td class="status">
                                                @if($data -> status  == '1' )
                                                    <span value="1">启用</span>
                                                @else
                                                    <span value="0">禁用</span>
                                                @endif
                                            </td>
                                            <td><a href="{{ url('hair') }}/{{ $data -> hairid }}"><i class="fa fa-reorder"></i></a>　　<a href="{{url('hair')}}/{{ $data -> hairid }}/edit"><i class="fa fa-pencil"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:;" onclick="hair_delete(this,{{ $data -> hairid }})"><i class="fa fa-trash-o"></i></a>　<a href="{{ url('haircolorshow') }}/{{ $data -> hairid }}" class="btn btn-success">haircolor管理</a></td>
                                        </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                        <!-- /.box-body -->
                    </div>
                </div>
                {{  $datas -> links() }}
            </div>
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <!-- 在这里 写js函数-->
    <script type="text/javascript">
        //双击事件
        $(".status").dblclick(function(){
            //获取当前的用户uid
            var status = $(this).find('span').attr('value');
            if(status == '1'){
                var cstatus = '0';
            }else{
                var cstatus = '1';
            }
            var hairid = $(this).parent().find("input[name='hair[]']").val();
            var t = $(this);
            //进行ajax传值
            $.ajaxSetup({
                headers:{
                    'X-CSRF-TOKEN':$('meta[name="csrf-token"]').attr('content')
                }
            });
            $.ajax({
                url:"{{ url('hair_status') }}",
                type:"POST",
                data:{hairid:hairid,cstatus:cstatus},
                success:function(data){
                    if(data.status == 'success'){
                        if(cstatus == '0'){
                            t.find('span').html('禁用');
                            t.find('span').attr('value','0');
                        }else{
                            t.find('span').html('启用');
                            t.find('span').attr('value','1');
                        }
                    }else{
                           alert('修改失败');
                    }
                },
            dataType:'json'
            });
        });
        function hair_delete(e,id){
            $.ajaxSetup({
                headers:{
                    'X-CSRF-TOKEN':$('meta[name="csrf-token"]').attr('content')
                }
            });
            var tr = $(e).closest("tr");
            if(confirm("确定要删除此条数据吗？"))
                $.ajax({
                    url:"{{ url('hair') }}/"+id,
                    url:"{{ url('hair') }}/"+id,
                    type:"DELETE",
                    data:{id:id},
                    success:function(data){
                        if(data.status == 'havechild'){
                            alert(data.msg);
                        }else if(data.status == 'success'){
                            alert(data.msg);
                            tr.remove();

                        }else{
                            alert(data.msg);
                        }
                    },
                    dataType:'json'
                });
        }
    </script>
@endsection


